package com.example.administrator.androidui4;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    class MYButtonListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "内部类点击事件处理", Toast.LENGTH_SHORT).show();
        }
    }

    String[] furits=new String[]{"苹果","榴莲","西瓜"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btnMyDiolog = findViewById(R.id.btn_mydialog);
        btnMyDiolog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyDialog dialog= new MyDialog(MainActivity.this);
                dialog.show();
            }
        });


        Button btnProgressDialog = findViewById(R.id.btn_progress_dialog);
        btnProgressDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
                progressDialog.setMessage("加载中");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                progressDialog.show();
               // progressDialog.dismiss();
            }
        });



        Button button1 = findViewById(R.id.btn_button1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "匿名内部类对象", Toast.LENGTH_SHORT).show();
            }
        });

        Button button2 = findViewById(R.id.btn_button2);
        button2.setOnClickListener(new MYButtonListener());


        RadioGroup rgSex = findViewById(R.id.rg_sex);
        rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                Toast.makeText(MainActivity.this, checkedId+"", Toast.LENGTH_SHORT).show();
            if(checkedId==R.id.rb_male){
                Toast.makeText(MainActivity.this, "男", Toast.LENGTH_SHORT).show();
            }
                if(checkedId==R.id.rb_female){
                    Toast.makeText(MainActivity.this, "女", Toast.LENGTH_SHORT).show();
                }
            }
        });

        Button btnAlertDialog = findViewById(R.id.btn_alert_dialog);
        btnAlertDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder buider = new AlertDialog.Builder(MainActivity.this);
                buider.setTitle("警告框");
                //buider.setMessage("你是否真的确认要删除吗");
             /*   buider.setSingleChoiceItems(furits, -1, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this, furits[which], Toast.LENGTH_SHORT).show();
                    }
                });*/
             buider.setMultiChoiceItems(furits, null, new DialogInterface.OnMultiChoiceClickListener() {
                 @Override
                 public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                     Toast.makeText(MainActivity.this, furits[which]+isChecked, Toast.LENGTH_SHORT).show();
                 }
             });
                buider.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this, "已删除", Toast.LENGTH_SHORT).show();
                    }
                });
                buider.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(MainActivity.this, "已取消", Toast.LENGTH_SHORT).show();
                    }
                });
                AlertDialog dialog = buider.create();
                dialog.show();
            }
        });
    }

    public void click(View view) {
        Toast.makeText(this, "按钮被打了", Toast.LENGTH_SHORT).show();
    }
}
